require(graphics)
library("gplots")

setwd("/Users/mathieu/Documents/workspace/Chromatin Conformation Analysis/Clustering/Output")

distanceMatrix <- read.table("interStructureDistanceMatrix.txt")

m <- as.matrix(distanceMatrix)

my.average <- function(d) hclust(d, method="average")

group.colors <- NULL
group.colors[1:250] <- colors()[563]		# blue
group.colors[251:500] <- colors()[555]		# red
group.colors[501:750] <- colors()[153]		# black
group.colors[751:1000] <- colors()[640]		# pink
group.colors[1001:1250] <- colors()[621]	# orange

group.colors[1:500] <- colors()[563]		# blue
group.colors[501:1000] <- colors()[555]		# red

group.colors[1:125] <- colors()[563]		# blue
group.colors[126:250] <- colors()[555]		# red

group.colors <- NULL
group.colors[1:100] <- colors()[563]		# blue
group.colors[101:200] <- colors()[555]		# red
group.colors[201:300] <- colors()[640]		# pink
group.colors[301:400] <- colors()[621]		# orange
group.colors[401:500] <- colors()[153]		# black
group.colors[501:600] <- colors()[107]		# purple
group.colors[601:700] <- colors()[151]		# brown
group.colors[701:800] <- colors()[142]		# yellow



group.colors[1:150] <- colors()[563]		# blue
group.colors[151:300] <- colors()[555]		# red

group.colors[225:225] <- colors()[153]		# black
group.colors[264:264] <- colors()[153]		# black


heatmap(m,symm=TRUE,ColSideColors=group.colors,labCol=NA,col=topo.colors(100),scale="none",hclustfun=my.average)



group.colors <- NULL
group.colors[1:100] <- colors()[563]		# blue
group.colors[101:200] <- colors()[555]		# red

group.colors[201:300] <- colors()[153]		# black

group.colors[301:400] <- colors()[621]		# orange
group.colors[301:400] <- colors()[640]		# pink
group.colors[401:500] <- colors()[153]		# black


my.average <- function(d) hclust(d, method="average")

heatmap(m,symm=TRUE,ColSideColors=group.colors,labRow=NA,labCol=NA,col=topo.colors(100),scale="none",hclustfun=my.average)

heatmap(m,symm=TRUE,ColSideColors=group.colors,col=topo.colors(100),scale="none",hclustfun=my.average)	# with structure index labels



pdf("heatmapOfClustering.pdf")
heatmap(m,symm=TRUE,ColSideColors=group.colors,labRow=NA,labCol=NA,col=topo.colors(100),scale="none",hclustfun=my.average)
dev.off()


pdf("heatmapOfClustering.pdf")
heatmap.2(m,symm=TRUE,ColSideColors=group.colors,labRows=NA,labCol=NA,col=topo.colors(100),scale="none",hclustfun=my.average, cexRow=0.25, cexCol=0.25, key=TRUE, density.info="none", trace="none", Colv=TRUE)
dev.off()